<?php
include ("../main/inc/global.inc.php");

require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
require_once (api_get_path(CONFIGURATION_PATH).'profile.conf.php');

api_block_anonymous_users(); // only users who are logged in can proceed

// Top part of the HTML
Display :: display_header('Edit file');

// Connect to sql
$link = mysql_connect("localhost", "root", "root");
mysql_select_db("dokeos_main", $link);
?>

<?php

// configuration
$file = $_POST['editfile_filePath'];
$fileId = $_POST['editfile_fileId'];
// check user access

$sql_query_history = "SELECT u.lastname, u.firstname, frh.diffpath 
FROM file_revision_history frh, user u
WHERE frh.fileid = " .$fileId ." 
AND u.user_id = frh.userid";
$result = mysql_query($sql_query_history, $link);

if (mysql_num_rows($result) == 0 ){
	echo "This file do not have any history yet. <br/>";
	exit();
} else {
	echo "<ul>";
	while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
		echo "<li>".$row[2].", edited by ".$row[0]." ".$row[1]."</li>";
?>
		<form name="showRevisionForm" action="history.php" method="post">
			<input name="diff_path" type="hidden" value="<?php echo $row[2]?>".>	
			<input name="editfile_filePath" type="hidden" value="<?php echo $file?>"/>
  		<input name="editfile_fileId" type="hidden" value="<?php echo $fileId?>"/>
			<input type="submit" value="Show Details" />
		</form>
<?php
	}
	echo "</ul>";
}

// read the textfile
if (isset($_POST['diff_path'])) {
	echo $_POST['diff_path'];
	$text = file_get_contents($_POST['diff_path']);
	echo $text;
}

?>
<?php
// Footer
Display :: display_footer();
?>
